<template>
    <a-modal :title="$t('文件共享类型')" v-model='isShow' @cancel='handleClose' width='480px' @ok='handleCreate'
        :cancelText="$t('Cancel')" :okText="$t('Sure')" :maskClosable='false' v-dragModal>
        <a-form-model ref="ruleForm" :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-form-model-item :label="$t('文件共享类型')">
                <a-radio-group v-model="form.type">
                    <a-radio v-for="item of typeGroup" :value="item.value" :key="item.value">{{ item.label
                    }}</a-radio>
                </a-radio-group>
            </a-form-model-item>
        </a-form-model>
    </a-modal>
</template>

<script>
export default {
    data() {
        return {
            isShow: false,
            labelCol: { span: 6 },
            wrapperCol: { span: 18 },
            form: {
                type: 1,
                dir_name: '',
            },
            typeGroup: [
                { value: 1, label: 'SMB/CIFS' },
                { value: 2, label: 'NFS' },
            ],
        };
    },
    methods: {
        handleCreate() {
            this.$refs.ruleForm.validate(async valid => {
                if (valid) {
                    if (this.form.type == 1) this.$router.push({ path: '/createShare', query: { dir_name: this.form.dir_name  }  })
                    else if (this.form.type == 2) {
                        this.$router.push({ query: { name: 'NFS', dir_name: this.form.dir_name  }  })
                        this.$emit('change-tab', this.form.dir_name)
                    }
                    this.isShow = false
                } else {
                    return false;
                }
            });
        },
        handleClose() {
            this.$refs['ruleForm'].resetFields();
            this.isShow = false
        },
    }
}
</script>